package love.contact;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * @author wangweike
 * @create_date 2011-12-24
 * @update_date 2011-12-24
 */

public class WebViewActivity extends BaseActivity
{
	static public final String URL="url";
	
	private WebViewClient webViewClient;
	private WebChromeClient webChromeClient;
	private String url;
	
	public void onCreate(Bundle icicle)
	{
		super.onCreate(icicle);   
		
		WebView webView=new WebView(this);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.setScrollBarStyle(0);//0 scrollbar on webview
		
		url=getIntent().getStringExtra(URL);
		if(url!=null)
		{
			webView.loadUrl(url);
		}
		else
		{
			String content=getIntent().getStringExtra("content");
			if(content!=null)
			{
				webView.loadData(content, "", "gbk");
			}
		}
		
		setContentView(webView);
		
		webViewClient=new WebViewClient()
		{
			public boolean shouldOverrideUrlLoading(WebView view, String url)  
			{
				return false;
			}
			
		    @Override
		    public void onPageStarted(WebView view, String url, Bitmap favicon)
		    {
		    }

            @Override
            public void onPageFinished(WebView view, String url)
            {
            }

            @Override
            public void onLoadResource(WebView view, String url)
            {
            }
		};
		
		webChromeClient=new WebChromeClient()
		{
			 public void onReceivedTitle(WebView view, String title)
			 {
				 setTitle(title);
			 }
		};
		
		webView.setWebViewClient(webViewClient);
		webView.setWebChromeClient(webChromeClient);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{		
		MenuItem menuItem=menu.add(0,0,0,"menuWeb");
		//menuItem.setIcon(R.drawable.ic_menu_add);
	
		super.onCreateOptionsMenu(menu);
		
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		super.onOptionsItemSelected(item);
		
		NavigationActivity navigationActivity=(NavigationActivity)getParent();
		Intent intent=new Intent(navigationActivity,MyGroupActivity.class);//.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		navigationActivity.pushActivity(intent);
		
		return true;
	}
}
